perm filename HAL.PAL[HAL,HE]20 blob sn#208425 filedate 1976-03-30 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.TITLE  AL INTERPRETER
C00006 00003	 program initialization
C00016 ENDMK
C⊗;
.TITLE  AL INTERPRETER

;These need only be looked at during the first pass:
    .IF1
        .INSRT HALHED.PAL[HAL,HE]

	STSW  FLOAT,1	;1 => put in the floating-string conversions
	STSW  KERNEL,1	;1 => use the kernel
	STSW  SMALLB,1	;1 => use the small block routines
	STSW  ONMONS,1	;1 => put in condition monitors
	STSW  GRAPHS,1	;1 => put in graph structure
	STSW  MOVING,1	;1 => assume the servo is loaded too
	STSW  INTLOAD,1	;1 => put in the interpreter
	STSW  ALAID,1	;1 => put in the ALAID debugging stuff
	STSW  DETECT,0	;1 => put in the collision detector only
	STSW  MAP,0	;1 => put in mapping capablity.  Obsolete.
	STSW  LBDEBUG,1	;1 => first word of any large block is address of maker.

        .INSRT K1DEF.PAL[11,SYS]
    .ENDC

. = INTRP

.INSRT HALIO.PAL[HAL,HE]

.IFNZ MAP
    .INSRT MAP.PAL[HAL,HE]
.ENDC

.INSRT LARGEB.PAL[HAL,HE]

MAINBL:	PDBLK 210,S	;Makes a process descriptor for main process

.IFNZ SMALLB		;Small block allocator
    .INSRT SMALLB.PAL[HAL,HE]
.ENDC

.IFNZ INTLOAD		;The interpreter
    .INSRT INTERP.PAL[HAL,HE]
    .IFZ MOVING
        .INSRT ARITH.PAL[HAL,HE]
        PUTLOC LSQRTF,SQRTF     ;Global declaration
    .IFF
	ONE: .WORD 40200,0	;1.0
    .ENDC
.ENDC

.IFNZ FLOAT		;The floating I/O
    .INSRT FLOAT.PAL[HAL,HE]
.ENDC

.IFNZ ALAID		;The debugging package
    FLOAT==1		;uses floating output
    .INSRT ALAID.PAL[HAL,HE]
.ENDC

.IFNZ GRAPHS		;Graph structure
    .INSRT GRAPHS.PAL[HAL,HE]
.ENDC


.IFNZ DETECT		;Collision detector
    .INSRT DETECT.PAL[HAL,HE]
.ENDC

;Data areas

ISTBLK:	.BLKW ISBS	;Dummy interpreter status block (used in linking only)
ENVLTH == 200
ENVIRO:	.BLKW ENVLTH	;Environment

	PUTLOC JOBDAT, MAINBL
	PUTLOC JOBSA, START
; program initialization

START:	
	;initialize the world
	JSR PC,FRINIT	;Initialize free storage
    .IFNZ SMALLB
	CALL SBINIT	;Initialize small block space
    .ENDC
    .IFNZ GRAPHS
	JSR PC,GSINIT	;Initialize graph structure
    .ENDC
    .IFNZ MOVING
	MOV #34,R0	;Get a device block
	JSR PC,GTFREE	;
	MOV R0,R1
	JSR PC,@LINTARM	;Initialize the arm code
    .ENDC
	JSR PC,IOINIT	;Initialize input-output

	;check to see that the PCODE is compatible
	CMP PCDVER,#PCVERSION	;Version compatible?
	BEQ ST2		;Yes
	HALERR STMES	;No
ST2:	CMP ARMVER,#VERSION	;Arm compatible?
	BEQ ST3		;Yes
	HALERR STMES1	;No

ST3:
	;set up the first interpreter
    .IFNZ INTLOAD	;Initialize the interpreter
	JSR PC,INTINIT	;Initialize the interpreter events
	MOV #ENVIRO,R0	;Clear out the envrironment
	MOV #ENVLTH,R1	;
ST1:	CLR (R0)+	;
	SOB R1,ST1	;
	MOV #ISBS,R0	;R0 ← Size (in words) of an interpreter status block
	JSR PC,GTFREE	;R0 ← LOC[new interpreter status block]
	CLR LEV(R0)	;new LEV ← 0
	MOV R0,NXTINT+ISTBLK	;Prime the interpreter list.
	CLR NXTINT(R0)	;
	MOV #PCODE,IPC(R0)	;new IPC ← interpreter start address
	MOV #ENVIRO,ENV(R0)	;new ENV ← ENVIRO
	EVMAK		;-(SP) ← event for EVT in this interpreter
	MOV (SP),EVT(R0);new EVT ← event just created.
	MOV R0,-(SP)	;Save LOC[new interpreter status block]
	MOV #INSTSZ,R0	;R0 ← Size needed for an interpreter stack
	JSR PC,GTFREE	;R0 ← LOC[new interpreter stack]
	MOV (SP)+,R1	;R1 ← LOC[new interpreter status block]
	MOV R0,STKBAS(R1)	;Store away new stack base
	ADD #2*INSTSZ,R0	;R0 ← LOC[top of new stack] (INSTSZ is in bytes)
	MOV R1,-(SP)	;Save R1
	MOV R0,-(SP)	;Save R0
	MOV #210,R0	;Room for process descriptor
	JSR PC,GTFREE	;R0 ← LOC[new process descriptor]
	MOV #UFPUSE+UGRSAV,PDBSTA(R0);Use floating point, use saved registers.
	MOV #420,UPDLEN(R0)	;Length of PCB
	MOV (SP)+,R1	;R1 ← LOC[new interpreter stack top]
	MOV R1,PDBR3(R0)	;Store away new interp stack pointer (reg 3)
	MOV (SP)+,R1		;R1 ← LOC[new ISB]
	MOV R0,PCB(R1)		;Store away LOC[PCB] in new ISB
	MOV R1,PDBR4(R0)	;Store away LOC[ISB] in reg 4 of PCB
    .IFNZ ALAID
	MOV R1,CURNAM	;This is the current interpreter
    .ENDC
	MOV SP,R1	;
	TST (R1)+	;
	MOV R1,PDBSP(R0)	;Store away the new stack pointer (reg 6)
	MOV #INTERP,PDBPC(R0);Store away the new PC
	MOV #376,UIMAP(R0)	;Map instruction space
        MOV #576,UDMAP(R0)  ;Sets data space to map 1, which puts phys 160000
	ADD #PDBSTA,R0	;Move R0 to the middle of the process descriptor
	SCHEDU R0,#INTERP,#1,#2;Cause the new process to be started, suspended
    .IFNZ ALAID
	JSR PC,ALINIT	;Initialize ALAID
    .ENDC
	EVWAIT 		;Wait for the return signal
	BCC  TST1	;All well?
	HALERR TSTMES	;No
TST1:	MOV #TSTME1,R0	;
	JSR PC,TYPSTR	;Say farewell
	DISMIS		;Go away

STMES:	ASCIE </INCOMPATIBLE PCODE VERSION.  PROCEED AT YOUR OWN RISK/>
STMES1:	ASCIE </INCOMPATIBLE ARM VERSION.  PROCEED AT YOUR OWN RISK/>
TSTMES: ASCIE </BAD RETURN FROM MAIN INTERPRETER/>
TSTME1: ASCIE </
ALL DONE NOW.  SEE YOU AROUND!
/>
;End of the interpreter calling sequence

.IFF		;do some test without the iterpreter
	.PRINT /Not loading the interpreter
/
	JSR PC,TEST	;Try out whatever test routine has been loaded.
	DISMIS		;
.ENDC

PATCH:  .BLKW 100

.IFNZ INTLOAD+GRAPHS
	PUTLOC LGETVAL, GETVAL
	PUTLOC LGETARG, GETARG
	PUTLOC LINVLDT, INVLDT
.ENDC

.IF2
	FOO==.
	.INFO <First location after interpreter = >,\FOO
	.IFL ARMCOD-FOO
	  .ERROR Interpreter runs into arm code.
	.ENDC
.ENDC

.END 

.IFNZ MOVING		;Ability to move arms
    ;. ← ARMCOD
    ;.INSRT ARM.PAL[11,BES]  This is to be overlayed, not assembled with.
    ;.INSRT ARMSOL.PAL[11,BES] To be overlayed, not assembled with.
.ENDC